<template>
  <el-dialog :close-on-click-modal='false' v-drag :title="$t('添加')" :v-if="dialogVisible" :visible.sync="dialogVisible" append-to-body width="550px" @close='close'>
    <el-table size='mini' ref="multipleTable" :data="tableData" tooltip-effect="dark" max-height="500px" top='20vh' style="width: 100%" @select="dialogCheck">
      <el-table-column type="selection" align='center' width="55">
      </el-table-column>
      <el-table-column :label="$t('关联用户')" align='center'>
        <template slot-scope="scope">{{ scope.row.qdn }}</template>
      </el-table-column>
    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submit" class="addSubmit">{{$t('确 定')}}</el-button>
      <el-button @click="close" class="addClose">{{$t('取 消')}}</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { searchUdnInfo } from '@/api/user/server'
export default {
  name: 'SearchDialog',
  data () {
    return {
      dialogVisible: false,
      qdnStr: '',
      tableData: []
    }
  },
  methods: {
    dialogCheck (selection, row) {
      this.$refs.multipleTable.clearSelection()
      if (selection.length === 0) { // 判断selection是否有值存在
        return
      }
      if (row) {
        this.qdnStr = row.qdn
        this.$refs.multipleTable.toggleRowSelection(row, true)
      }
    },
    init (data) {
      this.dialogVisible = true
      searchUdnInfo(data).then(res => {
        if (res.status === 0) {
          this.tableData = res.info
        }
      })
    },
    submit () {
      if (this.qdnStr) {
        this.$emit('getInfoRefresh', this.qdnStr)
        this.close()
      } else {
        this.$message({
          message: this.$t('请选择一条数据'),
          type: 'error'
        })
      }
    },
    close () {
      this.dialogVisible = false
      this.tableData = []
      this.qdnStr = ''
    }
  }
}
</script>
